package ckw;

import org.springframework.context.ApplicationContext;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

import ckw.config.ApplicationConfig;
import ckw.config.PersistenceConfig;
import ckw.config.PersistenceMySqlConfig;
import ckw.gui.MainWindow;
import ckw.utils.DummyDataProvider;
import core.utils.ConfigPropertiesHolder;
import core.utils.Property;

public class Application {

	public static void main(String[] args) {
		ApplicationContext context;
		if (ConfigPropertiesHolder.getInstance().getProperty(Property.EMBEDDED).equals("true")) {
			context = new AnnotationConfigApplicationContext(PersistenceConfig.class, ApplicationConfig.class);
		} else {
			context = new AnnotationConfigApplicationContext(PersistenceMySqlConfig.class, ApplicationConfig.class);
		}

		MainWindow mainWindow = context.getBean(MainWindow.class);
		if (ConfigPropertiesHolder.getInstance().getProperty(Property.HBM2DDL_AUTO).equals("create") && ConfigPropertiesHolder.getInstance().getProperty(Property.SAMPLE_DATA).equals("true"))
			context.getBean(DummyDataProvider.class).addSampleData();
		mainWindow.open();
		((ConfigurableApplicationContext) context).close();
	}
}
